import { CanDelegateCellRenderer } from "../../delegate/cell/CanDelegateCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { FlyFootBmp } from "../../mapUI/flyFoot/FlyFootBmp";
import { CanDelegateItemData } from "../../delegate/cell/CanDelegateItemData";
import { Cache } from "../../../cache/Cache";
import { CopyUtil } from "../../copy/CopyUtil";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { DelegateTaskStatus } from "../../delegate/DelegateTaskStatus";
import { DataEvent } from "../../../events/DataEvent";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
import { TaskTargetInfo } from "../../../model/TaskTargetInfo";
//class CanActiveDelegateCellRenderer
    
    export  class CanActiveDelegateCellRenderer extends CanDelegateCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            ObjCreate.createBg(0, 0, 190, 260, this);
            _typeLabel = ObjCreate.createLabel("", 0, 5, 190, 25, flash.text.TextFormatAlign.CENTER, this, true, 16742658);
            _typeLabel.setStyle("textFormat", new GTextFormat("黑体", 14, 16742658, true, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            _typeLabel.drawNow();
            _levelDes = ObjCreate.createLabel(Language.getString(69632), 15, 40, 70, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color1Uint);
            _levelDes.drawNow();
            _levelLabel = ObjCreate.createPriceLabel("", 95, 40, 65, 20, flash.text.TextFormatAlign.LEFT, this, true, 64773);
            _levelUnReachLabel = ObjCreate.createGTextField("", 0, 40, 70, 20);
            _levelUnReachLabel.htmlText = "<a href=\'event: click\'>" + HTMLUtil.addColor("[<u>" + Language.getString(69635) + "</u>]", "#FF0000") + "</a>";
            _levelUnReachLabel.toolTipData = HTMLUtil.addColor(Language.getString(69636), "#FFFFFF");
            _levelUnReachLabel.addEventListener(flash.events.TextEvent.LINK, onLevelUnReachClick);
            ObjCreate.createLabel(Language.getString(69851), 15, 70, 70, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960).drawNow();
            _conditionLabel = ObjCreate.createPriceLabel("", 90, 70, 130, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color2Uint);
            _conditionLabel.drawNow();
            _numStepper = ObjCreate.createPageSelecter(95, 100, this);
            _numStepper.addEventListener(flash.events.Event.CHANGE, onDelegateNumberChange);
            _numLabel = ObjCreate.createLabel(Language.getString(69662), 15, _numStepper.y, 70, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color5Uint);
            _numLabel.drawNow();
            ObjCreate.createLabel(Language.getString(69608), 15, 130, 70, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color1Uint).drawNow();
            _expLabel = ObjCreate.createPriceLabel("", 95, 130, 90, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color2Uint);
            _expVipLabel = ObjCreate.createPriceLabel("", 95, 162, 90, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color2Uint);
            _expDrugLabel = ObjCreate.createPriceLabel("", 95, 184, 90, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color2Uint);
            _expUseDrugLabel = ObjCreate.createGTextField("", 158, 184, 60, 20, this);
            _expUseDrugLabel.htmlText = HTMLUtil.addColor("<a href=\'event:\'><u>" + Language.getString(69673) + "</u></a>", "#FFFF00");
            _expUseDrugLabel.addEventListener(flash.events.TextEvent.LINK, onUseExpDrugLink);
            if (GlobalClass.hasRes(ImagesConst.DelegateTask_vipAdd)) 
            {
                setBitmap();
            }
            else 
            {
                LoaderHelp.addResCallBack(ResFileConst.delegateTask, setBitmap);
            }
            ObjCreate.createLabel(Language.getString(69659), 15, 206, 80, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color1Uint).drawNow();
            _expAddLabel = ObjCreate.createPriceLabel("", 95, 206, 90, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            _expAddLabel.toolTipData = HTMLUtil.addColor(Language.getString(69647), "#FFFFFF");
            _optBtn = ObjCreate.createGButton(Language.getString(69634), 58, 230, 75, 24, this, "ButtonSpecial");
            _optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClick);
            this._flyFoot = new FlyFootBmp();
            this._flyFoot.x = _optBtn.x + _optBtn.width - 8;
            this._flyFoot.y = _optBtn.y + 5;
            this._flyFoot.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            this.addChild(this._flyFoot);
            _nextLabelBtn = ObjCreate.createGTextField("", _optBtn.x + 78, _optBtn.y + 7, 50, 20, this);
            _nextLabelBtn.autoSize = flash.text.TextFieldAutoSize.LEFT;
            _nextLabelBtn.htmlText = "<a href=\'event:\'><u>" + HTMLUtil.addColor(Language.getString(69649), "#FFFF00") + "</u></a>";
            _nextLabelBtn.addEventListener(flash.events.TextEvent.LINK, onNextLabelBtnClick);
            _levelLabel.drawNow();
            _expLabel.drawNow();
            _expAddLabel.drawNow();
            _optBtn.drawNow();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            _data = arg1;
            if (data) 
            {
                loc1 = data as CanDelegateItemData;
                if (loc1.data) 
                {
                    if (!loc1.copy) 
                    {
                        return;
                    }
                    this._target = Cache.instance.scene.getNearlyNpcByCopyId(loc1.copy.code);
                    loc2 = CopyUtil.getCopyNumByDay(loc1.copy) - Cache.instance.copy.getHasEnterNumById(loc1.copy.code);
                    _numStepper.maxPage = loc2 < 1 ? 1 : loc2;
                    _numStepper.currentPage = loc1.count;
                    _expVip = Cache.instance.delegateTask.getExpAddVIP();
                    _expDrug = Cache.instance.delegateTask.getExpAddDrug();
                    if (loc1.moneyType != EPrictUnit._EPriceUnitCoin) 
                    {
                        _conditionLabel.htmlText = HTMLUtil.addColor(Language.getString(69857), GlobalStyle.color5);
                        _levelLabel.htmlText = HTMLUtil.addColor(Language.getStringByParam(69640, loc1.copy.enterMinLevel), GlobalStyle.color1);
                        _typeLabel.htmlText = HTMLUtil.addColor(Language.getString(69856), "#FF7902");
                        _expBase = loc1.data.tsweepUp.experience * 2;
                    }
                    else 
                    {
                        loc3 = loc1.data.status != DelegateTaskStatus.CanNotDelegate ? GlobalStyle.color5 : "#FF0000";
                        _conditionLabel.htmlText = HTMLUtil.addColor(loc1.data.tsweepUp.conditionDesc, loc3);
                        _levelLabel.htmlText = HTMLUtil.addColor(Language.getStringByParam(69640, loc1.data.tsweepUp.levelLimit), GlobalStyle.color1);
                        _typeLabel.htmlText = HTMLUtil.addColor(Language.getString(69853), "#FF7902");
                        _expBase = loc1.data.tsweepUp.experience;
                    }
                }
            }
            this.updateLabels();
            this.updateStatus();
            return;
        }

        protected /* override */ updateLabels(): void
        {
            _expLabel.htmlText = HTMLUtil.addColor("" + _expBase * _numStepper.currentPage, "#00FF00");
            _expVipLabel.htmlText = HTMLUtil.addColor(Math.round(_expBase * _numStepper.currentPage * _expVip / 100) + " [" + _expVip + "%]", "#00BEFF");
            _expDrugLabel.htmlText = HTMLUtil.addColor(Math.round(_expBase * _numStepper.currentPage * _expDrug / 100) + " [" + _expDrug + "%]", "#FF00FF");
            _expAddLabel.htmlText = HTMLUtil.addColor(Math.round((_expBase + _expBase * (_expVip + _expDrug) / 100) * _numStepper.currentPage) + "", "#FF7902");
            return;
        }

        protected /* override */ updateStatus(): void
        {
            var loc1=data as CanDelegateItemData;
            if (loc1.isReachLevel()) 
            {
                if (_levelUnReachLabel.parent) 
                {
                    _levelUnReachLabel.parent.removeChild(_levelUnReachLabel);
                }
            }
            else 
            {
                if (!_levelUnReachLabel.parent) 
                {
                    this.addChild(_levelUnReachLabel);
                }
                _levelUnReachLabel.x = _levelLabel.x + _levelLabel.textField.textWidth + 5;
            }
            if (loc1.data.status != DelegateTaskStatus.CanDelegate) 
            {
                _optBtn.enabled = false;
            }
            else 
            {
                _optBtn.enabled = true;
            }
            if (loc1.moneyType != EPrictUnit._EPriceUnitCoin) 
            {
                _optBtn.styleName = "LinkButton";
                _optBtn.label = Language.getString(69858);
                _nextLabelBtn.visible = false;
                this._flyFoot.visible = true;
            }
            else 
            {
                _optBtn.styleName = "ButtonSpecial";
                _optBtn.label = Language.getString(69661);
                _nextLabelBtn.visible = true;
                this._flyFoot.visible = false;
            }
            _optBtn.drawNow();
            return;
        }

        protected /* override */ onOptBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (data) 
            {
                loc1 = data as CanDelegateItemData;
                if (_optBtn.label != Language.getString(69858)) 
                {
                    this.dispatchEvent(new DataEvent(GModuleEvent.StartDelegateTaskFree, {"data": loc1.data.tsweepUp, "count": _numStepper.currentPage, "double": false}, false, true, true));
                }
                else 
                {
                    AIManager.onAutoPathAIControl(this._target);
                }
            }
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1): void
        {
            AIManager.onAIControl(this._target, AIType.AI_Convey);
            return;
        }

        /* internal */ /* var */_target: TaskTargetInfo;

        /* internal */ /* var */_flyFoot: FlyFootBmp;
    }
